#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e6 + 10;

int deg[N],n,f[N],ans[N],top,cent;
vector < int > G[N];

void dfs(int x,int p = 0) {
	f[x] = deg[x] <= 2 ? x : 2e9;
	for(auto y : G[x]) if(y ^ p) dfs(y,x),f[x] = min(f[x],f[y]);
}

void getdown(int x,int p) {
	vec son; for(auto y : G[x]) if(y != p) son.pb(y);
	if(!son.size()) ans[++top] = x;
	if(son.size() == 1) {
		int l = son[0];
		if(f[l] < x) getdown(l,x),ans[++top] = x;
		else ans[++top] = x,getdown(l,x);
	}
	if(son.size() == 2) {
		int l = son[0],r = son[1]; if(f[l] > f[r]) swap(l,r);
		getdown(l,x),ans[++top] = x,getdown(r,x);
	}
}

void getup(int x,int p = 0) {
	vec son; for(auto y : G[x]) if(y != p) son.pb(y);
	ans[++top] = x;
	if(son.size() == 1) {
		int l = son[0];
		if(f[l] < l) getdown(l,x);
		else getup(l,x);
	}
	if(son.size() == 2) {
		int l = son[0],r = son[1];
		if(f[l] > f[r]) getdown(r,x),getup(l,x);
		else getdown(l,x),getup(r,x);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++) {
		deg[i] = in; if(deg[i] <= 2) cent = cent ? cent : i;
		for(int j = 1;j <= deg[i];j++) G[i].pb(in);
	}
	dfs(cent); getup(cent);
	for(int i = 1;i <= top;i++) printf("%d ",ans[i]);
	return 0;
}
